﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpObjects.SearchEngine.Common.Search;

namespace SharpObjects.SearchEngine.Common.QueryConstraints
{
    [Serializable]
    public class SimilarVectorQueryConstraint : IQueryConstraint
    {
        public SimilarVectorQueryConstraint()
        {
            this.Vector = new List<TermVectorItem>();
            this.ConstraintId = Guid.NewGuid();
        }

        public Guid ConstraintId { get; set; }

        public string FieldName { get; set; }
        public List<TermVectorItem> Vector { get; set; }
        public bool ShowFieldName { get; set; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            for (int k = 0; k < this.Vector.Count; k++ )
            {
                sb.Append(this.Vector[k]);

                if(k < (this.Vector.Count - 1))
                {
                    sb.Append(", ");
                }
            }

            if(ShowFieldName)
            {
                return string.Format("{0}: [{1}]", this.FieldName, sb.ToString());
            }
            else
            {
                return string.Format("[{0}]", sb.ToString());
            }
        }
    }
}
